<%@ page language="java" pageEncoding="UTF-8" import="com.chinapost.util.AuthUtil"%>
<%@ taglib prefix="my" uri="/WEB-INF/tlds/permission.tld" %>
<%
	AuthUtil authUtil = new AuthUtil(session);
%>
<script type="text/javascript">
	var kind_datagrid;
	$(function() {
		kind_datagrid = $('#kind_manager_datagrid').datagrid({
			url : '${pageContext.request.contextPath}/kindAction!do_datagrid.action',
			title:'业务种类列表',
			pagination : true,
			pageSize : 20,
			pageList : [  10, 20, 30, 40, 50 ],
			border : true,
			fit : true,
			fitColumns : true,
			idField : 'cid',
			sortName : 'cid',
			sortOrder : 'asc',
			checkOnSelect : false,
			selectOnCheck : true,
			columns : [ [{
				checkbox : true  
			}, {
				title : '编号',
				field : 'cid',
				width : 100,
				align : "center"
			}, {
				title : '业务种类名称',
				field : 'cname',
				align : "center",
				width : 160
			},  {
				field : 'action',
				title : '操作',
				width : 100,
				align : 'center',
				formatter : function(value, row, index) {
					var str='';
                	<%if (authUtil.isAuth("/kindAction!kindEdit.action")){%>
                	str += sy.fs('<img onclick="kindEdit(\'{0}\');" src="{1}" style="cursor: pointer;" title="修改"/>&nbsp;',row.cid,'${pageContext.request.contextPath}/css/themes/icons/pencil.png');
                	<%}%>
                	<%if (authUtil.isAuth("/kindAction!delete.action")){%>
                	str += sy.fs('<img onclick="kindDelete(\'{0}\');" src="{1}" style="cursor: pointer;" title="删除"/>&nbsp;',row.cid,'${pageContext.request.contextPath}/css/themes/icons/no.png');
                	<%}%>
                	return str;
				}
			} ] ],
			toolbar : '#kind_toolbar'
		});
	});

	function kindEdit(cid) {
		if (cid != undefined) {
			$('#kind_manager_datagrid').datagrid('unselectAll');
			$('#kind_manager_datagrid').datagrid('selectRecord', cid);
		}
		var rows = $('#kind_manager_datagrid').datagrid('getSelected');
		var p = parent.sy.dialog({
			title : '修改业务种类',
			iconCls : 'icon-edit',
			href : '${pageContext.request.contextPath}/kindAction!kindEdit.action',
			width : 380,
			height : 200,
			buttons : [ {
				text : '保存',
				iconCls : 'icon-save',
				handler : function() {
					var f = p.find('form');
					f.form('submit', {
						url : '${pageContext.request.contextPath}/kindAction!edit.action',
						success : function(d) {
							var json = $.parseJSON(d);
							if (json.success) {
								kind_datagrid.datagrid('reload');
								p.dialog('close');
							}
							parent.sy.messagerShow({
								msg : json.msg,
								title : '提示'
							});
						}
					});
				}
			} ],
			onLoad : function() {
				var f = p.find('form');
				f.form('load', rows);
				f.find('input[name="cname"]').select();
			}
		});
	};
	function kindAppend() {
		var p = parent.sy.dialog({
			title : '添加业务种类',
			iconCls : 'icon-append',
			href : '${pageContext.request.contextPath}/kindAction!kindAdd.action',
			width : 380,
			height : 200,
			buttons : [ {
				text : '保存',
				iconCls : 'icon-save',
				handler : function() {
					var f = p.find('form');
					f.form('submit', {
						url : '${pageContext.request.contextPath}/kindAction!add.action',
						success : function(d) {
							var json = $.parseJSON(d);
							if (json.success) {
								kind_datagrid.datagrid('reload');
								p.dialog('close');
							}
							parent.sy.messagerShow({
								msg : json.msg,
								title : '提示'
							});
						}
					});
				}
			} ],
			onLoad : function() {
				p.find('form input[name="cid"]').focus();
			}
		});
	}

	function kindDelete(cid) {
		parent.sy.messagerConfirm('请确认', '是否删除当前记录？', function(r) {
			if (r) {
				$.ajax({
					url : '${pageContext.request.contextPath}/kindAction!delete.action',
					data : {
						cid : cid
					},
					dataType : 'json',
					success : function(d) {
						kind_datagrid.datagrid('load');
						$('#kind_manager_datagrid').datagrid('uncheckAll').datagrid('unselectAll').datagrid('clearSelections');
						parent.sy.messagerShow({
							title : '提示',
							msg : d.msg
						});
					}
				});
			}
		});
	}

</script>




<table id="kind_manager_datagrid"></table>
<div id="kind_toolbar" style="display: none;" >
<table  class="toolbar" >
	<tr>
		<my:per url="/kindAction!kindAdd.action">
		<td><a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'icon-append',plain:true" onclick="kindAppend();">新增</a></td>
		<td><div class="datagrid-btn-separator"></div></td>
		</my:per>
	</tr>
</table>
</div>

